package cn.java75.sp.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

/**
 * @author oldliu
 * @since 1.0
 */
public class LoginUser implements UserDetails {

    private Admin admin;
    public LoginUser(){

    }
    public LoginUser(Admin a){
        this.admin=a;
    }
    public LoginUser(Admin a,Set<RoleRight> p){
        this.admin=a;
        this.permissions=p;
    }
    /**
     * 权限列表
     */
    private Set<RoleRight> permissions;

    @Override//角色集合，我们一般直接控制权限
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return permissions;
    }

    @Override
    public String getPassword() {
        return this.admin.getPassword();
    }

    @Override
    public String getUsername() {
        return this.admin.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
